package com.menchao.carsales.service.impl;

import com.menchao.carsales.common.http.ResponseData;
import com.menchao.carsales.dao.EmployeeMapper;
import com.menchao.carsales.pojo.Employee;
import com.menchao.carsales.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.servlet.function.ServerResponse;

/**
 * Porject: carsales
 * Date: 2021/7/13
 * Author: menchao
 * Description:
 */
@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public ResponseData<Employee> login(Integer userId, String password) {
        int resultCount = employeeMapper.checkUserId(userId);
        if (resultCount == 0){
            return ResponseData.errorMessage("用户不存在");
        }
        Employee employee = employeeMapper.selectLogin(userId, password);
        if (employee == null) {
            // 查询结果为空
            return ResponseData.errorMessage("密码错误");
        }
        //employee.setPassword(StringUtils.EMPTY);
        return ResponseData.success("登录成功", employee);
    }
}
